package com.ruoyi.web.controller.admin.design;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.dto.DesignerAddDto;
import com.ruoyi.system.dto.DesignerSeleteDto;
import com.ruoyi.system.service.DesignerService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/admin/designer")
public class AdminDesignerController {


    @Resource
    private DesignerService designerService;

    /**
     * 设计师新增
     */
    @PostMapping("/add")
    public AjaxResult addDesigner(@RequestParam("file") MultipartFile file,
                                  @RequestParam(value = "name", required = false) String name,
                                  @RequestParam(value = "employmentAge", required = false) Integer employmentAge,
                                  @RequestParam(value = "caseNumber", required = false) Long caseNumber,
                                  @RequestParam(value = "workTime", required = false) Date workTime,
                                  @RequestParam(value = "recommendeValue", required = false) Integer recommendeValue,
                                  @RequestParam(value = "status", required = false) String status) {
        DesignerAddDto dto = new DesignerAddDto();
        dto.setName(name);
        dto.setEmploymentAge(employmentAge);
        dto.setCaseNumber(caseNumber);
        dto.setWorkTime(workTime);
        dto.setRecommendeValue(recommendeValue);
        dto.setStatus(status);
        return AjaxResult.success(designerService.addDesigner(file,dto));
    }


    /**
     * 设计师逻辑删除
     */
    @PostMapping("/delete")
    public AjaxResult deleteDesigner(Long id) {
        return AjaxResult.success(designerService.deleteDesigner(id));
    }

    /**
     * 设计师编辑
     */
    @PostMapping("/edit")
    public AjaxResult editDesigner(@RequestBody DesignerAddDto dto) {
        return AjaxResult.success(designerService.editDesigner(dto));
    }

    /**
     * 设计师模糊搜索
     */
    @PostMapping("/query")
    public AjaxResult queryDesigner(@RequestBody DesignerSeleteDto dto) {
        return AjaxResult.success(designerService.queryDesigner(dto));
    }

    /**
     * 设计师推荐值排序
     */
    @PostMapping("/condition")
    public AjaxResult queryDesignerByValue() {
        return AjaxResult.success(designerService.queryDesignerByValue());
    }

    /**
     * 设计师详情
     */
    @GetMapping("/query/detail")
    public AjaxResult queryDesignerDetail(String id) {
        return AjaxResult.success(designerService.queryDesignerDetail(id));
    }
    /**
     * 设计师数据同步
     */
    @PostMapping("/synchronize/designer")
    public AjaxResult synchronizeDesigner(Long id){
        return AjaxResult.success(designerService.synchronizeDesigner(id));
    }
}
